package com.koron.plan.web.patrolplan.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.annocation.CasUser;
import com.koron.common.core.interceptor.OrderByInterceptor;
import com.koron.plan.web.patrolplan.bean.query.PatrolPointQuery;
import com.koron.plan.web.patrolplan.bean.vo.PatrolPlanPointDetailVO;
import com.koron.plan.web.patrolplan.bean.vo.PatrolPlanPointVO;
import com.koron.plan.web.patrolplan.service.PatrolPlanPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author twcao
 * @title: PatrolPlanPointController
 * @projectName GDH_EAM_V2
 * @description: 巡视点
 * @date 2021/10/278:41
 */
@RestController
@RequestMapping("/patrol/point")
@Api(tags = "巡视计划-巡视点")
public class PatrolPlanPointController {

    @Autowired
    private PatrolPlanPointService pointService;

    @GetMapping("/selectOne")
    @ApiOperation("根据巡视点id查询详情")
    @ApiImplicitParam(name = "pointId", value = "巡视点id", required = true, dataType = "String")
    public Response<PatrolPlanPointDetailVO> selectOne(@CasUser @ApiIgnore EamUser user, @RequestParam String pointId) {
        return Response.succ(ADOConnection.runTask(user.getCurrDs(), pointService, "queryById", PatrolPlanPointDetailVO.class, pointId));
    }

    @GetMapping("/queryList")
    @ApiOperation("巡视点列表")
    public Response<PageInfo<PatrolPlanPointVO>> queryList(@CasUser @ApiIgnore EamUser user, PatrolPointQuery query) {
        OrderByInterceptor.setOrderBy(query.getOrders());
        PageHelper.startPage(query.getPage(), query.getPageSize());
        List<PatrolPlanPointVO> list = ADOConnection.runTask(user.getCurrDs(), pointService, "queryList", List.class, query);
        return Response.succ(new PageInfo<>(list));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新巡视点")
    public Response<PatrolPlanPointDetailVO> saveOrUpdate(@CasUser @ApiIgnore EamUser user, @RequestBody PatrolPlanPointDetailVO point) {
        return Response.succ(ADOConnection.runTask(user.getCurrDs(), pointService, "saveOrUpdate", PatrolPlanPointDetailVO.class, point));
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("根据巡视点id删除巡视点")
    @ApiImplicitParam(name = "pointId", value = "巡视点id", required = true, dataType = "String")
    public Response<Boolean> deleteById(@CasUser @ApiIgnore EamUser user, @RequestParam String pointId) {
        return Response.succ(ADOConnection.runTask(user.getCurrDs(), pointService, "hiddenById", Boolean.class, pointId));
    }
}
